package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.company.EnterpriseScoreListFormBean;
import com.info.zhiduoduo.admin.model.formbean.project.AddEditTemplateFormBean;
import com.info.zhiduoduo.admin.model.formbean.project.TemplateListFormBean;
import com.info.zhiduoduo.admin.model.formbean.system.*;
import com.info.zhiduoduo.admin.service.SystemService;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.dto.system.CityCategoryOneDto;
import com.info.zhiduoduo.repository.dto.system.InvoiceCategoryOneDto;
import com.info.zhiduoduo.repository.entity.crm.CrmSystemDict;
import com.info.zhiduoduo.repository.entity.system.EnterpriseIndustry;
import com.info.zhiduoduo.repository.entity.system.SystemManager;

import com.info.zhiduoduo.shiro.util.PasswordMD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "系统接口")
@RestController
@RequestMapping("/sys")
public class SystemController {

	@Autowired
	SystemService systemService;

	//----------------------角色--------

	/**
	 添加角色

	 @param formBean
	 @return
	 */
	@PostMapping("/saveSystemRole")
	public SmartResult saveSystemRole(@RequestBody BaseSimpleFormBean<SaveSystemRoleFormBean> formBean) {
		return systemService.saveSystemRole(formBean);
	}

	/**
	 查看角色列表

	 @return
	 */
	@RequestMapping("/querySystemRolePage")
	public SmartResult querySystemRolePage() {
		return systemService.querySystemRolePage();
	}

	/**
	 查看角色详情

	 @param formBean
	 @return
	 */
	@PostMapping("/getSystemRoleById")
	public SmartResult getSystemRoleById(@RequestBody BaseSimpleFormBean<GetSystemRoleFormBean> formBean) {
		return systemService.getSystemRoleById(formBean);
	}

	/**
	 编辑角色

	 @param formBean
	 @return
	 */
	@PostMapping("/updateSystemRole")
	public SmartResult updateSystemRole(@RequestBody BaseSimpleFormBean<UpdateSystemRoleFormBean> formBean) {
		return systemService.updateRole(formBean);
	}

	/**
	 删除角色

	 @param formBean
	 @return
	 */
	@PostMapping("/deleteSystemRole")
	public SmartResult deleteSystemRole(@RequestBody BaseSimpleFormBean<GetSystemRoleFormBean> formBean) {
		return systemService.deleteSystemRole(formBean);
	}

	@PostMapping("/menus")
	public SmartResult getSystemMenus(@RequestBody BaseSimpleFormBean formBean) {
		return systemService.getsystemMenus(formBean);
	}

	//-----------------账户--------------

	/**
	 添加账户

	 @param formBean
	 @return
	 */
	@PostMapping("/saveManager")
	public SmartResult saveManager(@RequestBody BaseSimpleFormBean<SaveManagerFormBean> formBean) {
		return systemService.saveManager(formBean);
	}

	/**
	 查看账户列表

	 @return
	 */
	@RequestMapping("/queryManagerPage")
	public SmartResult queryManagerPage() {
		return systemService.queryManagerPage();
	}

	/**
	 查看账户详情

	 @param formBean
	 @return
	 */
	@PostMapping("/getManagerById")
	public SmartResult getManagerById(@RequestBody BaseSimpleFormBean<GetManagerFormBean> formBean) {
		return systemService.getManagerById(formBean);
	}

	/**
	 编辑账户

	 @param formBean
	 @return
	 */
	@PostMapping("/updateManager")
	public SmartResult updateManager(@RequestBody BaseSimpleFormBean<UpdateManagerFormBean> formBean) {
		return systemService.updateManager(formBean);
	}

	/**
	 删除账户

	 @param formBean
	 @return
	 */
	@PostMapping("/deleteManager")
	public SmartResult deleteManager(@RequestBody BaseSimpleFormBean<GetManagerFormBean> formBean) {
		return systemService.deleteManager(formBean);
	}

	/**
	 登录

	 @param formBean
	 @return
	 */
	@ZddLog(name = "登录")
	@PostMapping("/login")
	public SmartResult login(@RequestBody BaseSimpleFormBean<LoginFormBean> formBean) {
		return systemService.login(formBean);
	}

	@PostMapping("/updatepassword")
	public SmartResult updatePassword() {
		new SystemManager().selectAll().stream().forEach(m->{
			String password = m.getPassword();
			String md5Pwd = PasswordMD5Util.MD5Pwd(m.getLoginname(), password);
			// m.setMd5password(md5Pwd);
			m.updateById();
		});

		return new SmartResult();
	}

	/**
	 账户冻结解冻

	 @param formBean
	 @return
	 */
	@PostMapping("/updateManagerState")
	public SmartResult updateManagerState(@RequestBody BaseSimpleFormBean<UpdateManagerStateFormBean> formBean) {
		return systemService.updateManagerState(formBean);
	}

	@ApiModelProperty("切换后台")
	@PostMapping("/switch")
	public SmartResult switchAdmin(@Valid @RequestBody BaseSimpleFormBean<SwitchFormBean> formBean) {
		return systemService.switchAdmin(formBean);
	}

	//--------------------行业分类与经营范围-----------

	/**
	 添加一级的

	 @param formBean
	 @return
	 */
	@PostMapping("/saveTradecategoryOne")
	public SmartResult saveTradecategoryOne(@RequestBody BaseSimpleFormBean<SaveTradecategoryOneFormBean> formBean) {
		return systemService.saveTradecategoryOne(formBean);
	}

	/**
	 添加二级的

	 @param formBean
	 @return
	 */
	@PostMapping("/saveTradecategoryTwo")
	public SmartResult saveTradecategoryTwo(@RequestBody BaseSimpleFormBean<SaveTradecategoryTwoFormBean> formBean) {
		return systemService.saveTradecategoryTwo(formBean);
	}

	/**
	 查看一级的全部

	 @return
	 */
	@RequestMapping("/queryTradecategoryOne")
	public SmartResult queryTradecategoryOne() {
		return systemService.queryTradecategoryOne();
	}

	/**
	 查看二级的根据 一级的id

	 @param formBean
	 @return
	 */
	@PostMapping("/queryTradecategoryTwo")
	public SmartResult queryTradecategoryTwo(@RequestBody BaseSimpleFormBean<QuseryTradecategoryTwoFormBean> formBean) {
		return systemService.queryTradecategoryTwo(formBean);
	}

	/**
	 编辑一级的

	 @param formBean
	 @return
	 */
	@PostMapping("/updateTradecategoryOne")
	public SmartResult updateTradtegoryOne(@RequestBody BaseSimpleFormBean<UpdateTradecategoryOneFormBean> formBean) {
		return systemService.updateTradecategoryOne(formBean);
	}

	/**
	 编辑二级的

	 @param formBean
	 @return
	 */
	@PostMapping("/updateTradecategoryTwo")
	public SmartResult updateTradecategoryTwo(@RequestBody BaseSimpleFormBean<UpdateTradecategoryTwoFormBean> formBean) {
		return systemService.updateTradecategoryTwo(formBean);
	}

	/**
	 查看二级的详情

	 @param formBean
	 @return
	 */
	@PostMapping("/getTradecategoryTwoById")
	public SmartResult getTradecategoryTwoById(@RequestBody BaseSimpleFormBean<GetTradecategoryTwoFormBean> formBean) {
		return systemService.getTradecategoryTwoById(formBean);
	}

	/**
	 删除二级的

	 @param formBean
	 @return
	 */
	@PostMapping("/deleteTradecategoryTwo")
	public SmartResult deleteTradecategoryTwo(@RequestBody BaseSimpleFormBean<GetTradecategoryTwoFormBean> formBean) {
		return systemService.deleteTradecategoryTwo(formBean);
	}

	/**
	 获取行业分类父子结果

	 @param formBean
	 @return
	 */
	@PostMapping("/getTradeCategory")
	public SmartResult getTradeCategory(@RequestBody BaseSimpleFormBean<GetTradecategoryTwoFormBean> formBean) {
		return systemService.getTradeCategory(formBean);
	}

	@ApiOperation("添加行业分类")
	@PostMapping("/addIndustry")
	public SmartResult addIndustry(@Valid @RequestBody BaseSimpleFormBean<AddIndustryFormBean> formBean) {
		return systemService.addIndustry(formBean);
	}

	@ApiOperation("删除行业分类")
	@PostMapping("/delIndustry")
	public SmartResult delIndustry(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return systemService.delIndustry(formBean);
	}

	@ApiOperation("查询行业分类列表")
	@PostMapping("/industryList")
	public SmartResult<EnterpriseIndustry> getIndustryList(@RequestBody BaseSimpleFormBean<String> formBean) {
		return systemService.getIndustryList(formBean);
	}

	//------------------------ 项目需求分类 -----------------------//
	@PostMapping("/allProjectCategoryList")
	public SmartResult getProjectCategoryList(@RequestBody BaseSimpleFormBean formBean) {
		return systemService.getAllProjectCategoryList(formBean);
	}

	@PostMapping("/twoProjectCategoryList")
	public SmartResult getTwoProjectCategoryList(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return systemService.getTwoProjectCategoryList(formBean);
	}

	@PostMapping("/addEditProjectCategory")
	public SmartResult addEditProjectCategory(@RequestBody BaseSimpleFormBean<AddProjectCategoryFormBean> formBean) {
		return systemService.addEditProjectCategory(formBean);
	}

	@PostMapping("/delProjectCategory")
	public SmartResult deleteProjectCategory(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return systemService.deleteProjectCategory(formBean);
	}

	/**
	 新增编辑项目模板
	 */
	@PostMapping("/addEditProjectTemplate")
	public SmartResult addEditProjectTemplate(@RequestBody BaseSimpleFormBean<AddEditTemplateFormBean> formBean) {
		return systemService.addEditProjectTemplate(formBean);
	}

	/**
	 获取模板列表
	 */
	@PostMapping("/projectTemplateList")
	public SmartResult getProjectTemplateList(@RequestBody BaseSimpleFormBean<TemplateListFormBean> formBean) {
		return systemService.getProjectTemplateList(formBean);
	}

	/**
	 删除项目模板
	 */
	@PostMapping("/delProjectTemplate")
	public SmartResult delProjectTemplate(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return systemService.delProjectTemplate(formBean);
	}


	@ApiOperation("获取企业行业分类列表,GET方式")
	@GetMapping("/enterpriseIndustryList")
	public SmartResult<EnterpriseIndustry> getEnterpriseIndustryList() {
		return systemService.getEnterpriseIndustryList();
	}

	@ApiOperation("获取crm系统配置列表,GET方式")
	@GetMapping("/crmSystemDictList")
	public SmartResult<Map<Integer, List<CrmSystemDict>>> getCrmSystemDictList(@ApiParam("配置类型type,逗号分隔 ") @RequestParam(value = "typies") String typies) {
		return systemService.CrmSystemDictList(typies);
	}


	/** =========================== 开票内容 分类 =============================  */
	/**
	 添加一级的 开票内容
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/saveInvoiceCategoryOne")
	@ApiOperation("添加一级的 开票内容")
	public SmartResult saveInvoiceCategoryOne(@RequestBody @Validated BaseSimpleFormBean<SaveInvoiceCategoryFormBean> baseSimpleFormBean) {
		return systemService.saveInvoiceCategoryOne(baseSimpleFormBean);
	}

	/**
	 添加二级的
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/saveInvoiceCategoryTwo")
	@ApiOperation("添加二级的 开票内容")
	public SmartResult saveInvoiceCategoryTwo(@RequestBody @Validated BaseSimpleFormBean<SaveInvoiceCategoryTwoFormBean> baseSimpleFormBean) {
		return systemService.saveInvoiceCategoryTwo(baseSimpleFormBean);
	}

	/**
	 查看一级分类 开票内容列表
	 @return
	 */
	@PostMapping("/queryInvoiceCategoryOneList")
	@ApiOperation("查看一级分类 开票内容列表")
	public SmartResult<InvoiceCategoryOneDto> queryInvoiceCategoryOne(@RequestBody  BaseSimpleFormBean<QueryInvoiceCategoryFormBean> baseSimpleFormBean  ) {
		return systemService.queryInvoiceCategoryOneList(baseSimpleFormBean);
	}

	/**
	 查看二级的根据 一级的id
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/queryInvoiceCategoryTwo")
	@ApiOperation("查看二级列表 根据一级的id")
	public SmartResult queryInvoiceCategoryTwo(@RequestBody @Validated BaseSimpleFormBean<QueryInvoiceCategoryTwoFormBean> baseSimpleFormBean) {
		return systemService.queryInvoiceCategoryTwo(baseSimpleFormBean);
	}

	/**
	 编辑 一级/二级
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/updateInvoiceCategory")
	@ApiOperation("编辑 一级/二级 分类")
	public SmartResult updateInvoiceCategory(@RequestBody @Validated BaseSimpleFormBean<UpdateInvoiceCategoryFormBean> baseSimpleFormBean) {
		return systemService.updateInvoiceCategory(baseSimpleFormBean);
	}


	/**
	 查看二级的详情
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/getInvoiceCategoryById")
	@ApiOperation("查看详情根据id")
	public SmartResult getInvoiceCategoryTwoById(@RequestBody BaseSimpleFormBean<CategoryIdFormBean> baseSimpleFormBean) {
		return systemService.getInvoiceCategoryTwoById(baseSimpleFormBean);
	}

	/**
	 删除二级的 分类
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/deleteInvoiceCategoryTwo")
	@ApiOperation("删除二级的 分类")
	public SmartResult deleteInvoiceCategoryTwo(@RequestBody BaseSimpleFormBean<CategoryIdFormBean> baseSimpleFormBean) {
		return systemService.deleteInvoiceCategoryTwo(baseSimpleFormBean);
	}

	@PostMapping("/queryAllInvoiceCategory")
	@ApiOperation("获取一级二级列表")
	public SmartResult queryAllInvoiceCategory(@RequestBody BaseSimpleFormBean<InvoiceCategoryFormBean> baseSimpleFormBean){
		return systemService.queryAllInvoiceCategory(baseSimpleFormBean);
	}


	// ========================= 城市 开票类目       ====================

	/**
	 添加一级的 开票内容
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/saveCityCategoryOne")
	@ApiOperation("添加一级的 开票内容")
	public SmartResult saveCityCategoryOne(@RequestBody @Validated BaseSimpleFormBean<SaveCityCategoryFormBean> baseSimpleFormBean) {
		return systemService.saveCityCategoryOne(baseSimpleFormBean);
	}

	/**
	 添加二级的
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/saveCityCategoryTwo")
	@ApiOperation("添加二级的 开票内容")
	public SmartResult saveCityCategoryTwo(@RequestBody @Validated BaseSimpleFormBean<SaveCityCategoryTwoFormBean> baseSimpleFormBean) {
		return systemService.saveCityCategoryTwo(baseSimpleFormBean);
	}


	/**
	 编辑 一级/二级
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/updateCityCategory")
	@ApiOperation("编辑 一级/二级 分类")
	public SmartResult updateCityCategory(@RequestBody @Validated BaseSimpleFormBean<UpdateCityCategoryFormBean> baseSimpleFormBean) {
		return systemService.updateCityCategory(baseSimpleFormBean);
	}



	/**
	 删除一、二级的 分类
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/deleteCityCategory")
	@ApiOperation("删除一/二级的 分类")
	public SmartResult deleteCityCategory(@RequestBody BaseSimpleFormBean<Integer> baseSimpleFormBean) {
		return systemService.deleteCityCategory(baseSimpleFormBean);
	}

	@PostMapping("/queryAllCityCategory")
	@ApiOperation("获取一级二级列表")
	public SmartResult queryAllCityCategory(@RequestBody BaseSimpleFormBean<CityCategoryFormBean> baseSimpleFormBean){
		return systemService.queryAllCityCategory(baseSimpleFormBean);
	}

	/**
	 查看一级分类 开票内容列表
	 @return
	 */
	@PostMapping("/queryCityCategoryOneList")
	@ApiOperation("查看一级分类 开票内容列表")
	public SmartResult<CityCategoryOneDto> queryCityCategoryOneList(@RequestBody  BaseSimpleFormBean<QueryCityCategoryFormBean> baseSimpleFormBean  ) {
		return systemService.queryCityCategoryOneList(baseSimpleFormBean);
	}

	/**
	 查看二级的根据 一级的id
	 @param baseSimpleFormBean
	 @return
	 */
	@PostMapping("/queryCityCategoryTwo")
	@ApiOperation("查看二级列表 根据一级的id")
	public SmartResult queryCityCategoryTwo(@RequestBody @Validated BaseSimpleFormBean<Integer> baseSimpleFormBean) {
		return systemService.queryCityCategoryTwo(baseSimpleFormBean);
	}


	@PostMapping("/sensitiveVocabularyList")
	@ApiOperation("敏感词列表")
	public SmartResult sensitiveVocabularyList(@RequestBody BaseSimpleFormBean<String> formBean){
		return systemService.sensitiveVocabularyList(formBean);
	}
	@PostMapping("/addSensitiveVocabulary")
	@ApiOperation("添加一级敏感词")
	public SmartResult addSensitiveVocabulary(@RequestBody BaseSimpleFormBean<SensitiveVocabularyFromBean> formBean){
		return systemService.addSensitiveVocabulary(formBean);
	}
	@PostMapping("/deleteSensitiveVocabulary")
	@ApiOperation("删除敏感词")
	public SmartResult deleteSensitiveVocabulary(@RequestBody BaseSimpleFormBean<Integer> formBean){
		return systemService.deleteSensitiveVocabulary(formBean);
	}
	@PostMapping("/addSecondarySensitiveWords")
	@ApiOperation("添加二级敏感词")
	public SmartResult addSecondarySensitiveWords(@RequestBody BaseSimpleFormBean<AddSecondarySensitiveWordsFromBean> formBean){
		return systemService.addSecondarySensitiveWords(formBean);
	}

	@PostMapping("/queryRestraintTradeTime")
	@ApiOperation("查看系统限制交易的时间段")
	public SmartResult queryRestraintTradeTime() {
		return systemService.queryRestraintTradeTime();
	}

	@PostMapping("/editRestraintTradeTime")
	@ApiOperation("修改系统限制交易的时间段")
	public SmartResult editRestraintTradeTime(@RequestBody @Validated BaseSimpleFormBean<EditRestraintTradeFormBean> baseSimpleFormBean) {
		return systemService.editRestraintTradeTime(baseSimpleFormBean.getReqdata());
	}
}
